package com.pls.actionAdapter;

import com.pls.action.PlsService;
import com.pls.actionObjects.DeleteEmployeeSeatRequest;
import com.pls.actionObjects.DeleteEmployeeSeatResponse;
import com.pls.actionObjects.GetEmployeeDetailsRequest;
import com.pls.actionObjects.GetEmployeeDetailsResponse;
import com.pls.actionObjects.ReportRequest;
import com.pls.actionObjects.ReportResponse;
import com.pls.actionObjects.GetSeatCodeByFloorRequest;
import com.pls.actionObjects.GetSeatCodeByFloorResponse;
import com.pls.actionObjects.GetSeatMapByFloorRequest;
import com.pls.actionObjects.GetSeatMapByFloorResponse;
import com.pls.actionObjects.GetSeatMapByQuadrantRequest;
import com.pls.actionObjects.GetSeatMapByQuadrantResponse;
import com.pls.actionObjects.GetWorkstationMapByNameRequest;
import com.pls.actionObjects.GetWorkstationMapByNameResponse;
import com.pls.actionObjects.ValidateLoginRequest;
import com.pls.actionObjects.ValidateLoginResponse;
import com.pls.javabeans.DeleteEmployeeSeatBean;
import com.pls.javabeans.EmployeeDetailsBean;
import com.pls.javabeans.EmployeeWorkstationBean;
import com.pls.javabeans.GetSeatCodesByFloorBean;
import com.pls.javabeans.GetSeatMapByFloorBean;
import com.pls.javabeans.GetSeatMapByQuadrantBean;
import com.pls.javabeans.LoginBean;
import com.pls.javabeans.ReportSeatPlanBean;
import com.pls.actionObjects.SearchRequest;
import com.pls.actionObjects.SearchResponse;
import com.pls.constants.GenericConstants;
import com.pls.domain.Employee;
import com.pls.domain.EmployeeWorkstation;
import com.pls.domain.ReportSeatPlan;
import com.pls.javabeans.SearchBean;

/*
 * Mapper for PLS Action.
 * Returns javabeans.
 *  */
public class PlsAdapter {

	private static PlsService service;

	public PlsAdapter() {
		service = new PlsService();

	}

	public DeleteEmployeeSeatBean deleteEmployee(String employeeId,
			String seatCode) {

		// Declare the bean
		DeleteEmployeeSeatBean bean = new DeleteEmployeeSeatBean();

		// Declare the request needed
		DeleteEmployeeSeatRequest request = new DeleteEmployeeSeatRequest();

		// Declare the response needed
		DeleteEmployeeSeatResponse response = new DeleteEmployeeSeatResponse();

		// Call the service method
		response = service.deleteEmployeeSeat(request);

		// Map the result response to the bean
		bean.setValidationErrors(response.getValidationErrors());
		bean.setExceptionError(response.getExceptionError());
		bean.setSuccessful(response.isSuccessful());

		// return bean for use in GUI
		return bean;

	}

	// gets seatmap by quadrant
	public GetSeatMapByQuadrantBean getSeatMapByQuadrant(String location,
			String quadrant) {

		// Declare the bean
		GetSeatMapByQuadrantBean bean = new GetSeatMapByQuadrantBean();

		// Declare the request needed
		GetSeatMapByQuadrantRequest request = new GetSeatMapByQuadrantRequest();
		request.setLocation(location);
		request.setQuadrant(quadrant);

		// Declare the response needed
		GetSeatMapByQuadrantResponse response = new GetSeatMapByQuadrantResponse();

		// Call the service method
		response = service.getSeatmapByQuadrant(request);

		// Map the result response to the bean

		bean.setValidationErrors(response.getValidationErrors());
		bean.setExceptionError(response.getExceptionError());
		bean.setEmployeeResult(response.getEmployeeResult());
		bean.setLocationSeatMap(response.getLocationSeatMap());

		// return bean for use in GUI
		return bean;

	}

	// gets seatmap by floor
	public GetSeatMapByFloorBean getSeatMapFloor(String location, String floor) {

		// Declare the bean
		GetSeatMapByFloorBean bean = new GetSeatMapByFloorBean();

		// Declare the request needed
		GetSeatMapByFloorRequest request = new GetSeatMapByFloorRequest();
		request.setFloor(floor);
		request.setLocation(location);

		// Declare the response needed
		GetSeatMapByFloorResponse response = new GetSeatMapByFloorResponse();

		// Call the service method
		response = service.getSeatmapByFloor(request);

		// Map the result response to the bean

		bean.setValidationErrors(response.getValidationErrors());
		bean.setExceptionError(response.getExceptionError());
		bean.setLocationSeatMap(response.getLocationSeatMap());

		// return bean for use in GUI
		return bean;

	}

	public SearchBean search(String searchQuery) {

		// Declare the bean
		SearchBean bean = new SearchBean();

		// Declare the request needed
		SearchRequest request = new SearchRequest();

		// Declare the response needed
		SearchResponse response = new SearchResponse();

		// Map The request
		request.setSearchQuery(searchQuery);
		
		// Call the service method
		response = service.search(request);

		// Map the result response to the bean
		bean.setValidationErrors(response.getValidationErrors());
		bean.setExceptionError(response.getExceptionError());
		bean.setEmployeeResult(response.getEmployeeResult());
		bean.setSearchResults(response.getSearchResults());
		bean.setLocationSeatMap(response.getLocationSeatMap());

		// return bean for use in GUI
		return bean;

	}
	
	public LoginBean login(String emailAddress, String password){
	
		
		// Declare the bean
		LoginBean bean = new LoginBean();

		// Declare the request needed
		ValidateLoginRequest request = new ValidateLoginRequest();

		// Declare the response needed
		ValidateLoginResponse response = new ValidateLoginResponse();
		
		// Call the service method
		request.setEmailAddress(emailAddress);
		request.setPassword(password);
		request.setLoginType(GenericConstants.NORMAL_LOGIN_TYPE);
		
		// Call the service method
		response = service.validateLogin(request);
		
		
		// Map the result response to the bean
		bean.setEmployeeWorksation(response.getEmployeeWorkstation());
		
		// return bean for use in GUI
		return bean;
	}
	
	public LoginBean login(String emailAddress){
		LoginBean bean = new LoginBean();

		// Declare the request needed
		ValidateLoginRequest request = new ValidateLoginRequest();

		// Declare the response needed
		ValidateLoginResponse response = new ValidateLoginResponse();
		
		// Call the service method
		request.setEmailAddress(emailAddress);
		request.setLoginType(GenericConstants.GOOGLE_LOGIN_TYPE);
		
		// Call the service method
		response = service.validateLogin(request);
		
		// Map the result response to the bean
		bean.setEmployeeWorksation(response.getEmployeeWorkstation());
		
		
		// return bean for use in GUI
		return bean;
		
	}
	
	public EmployeeDetailsBean getEmployeeDetails(String firstName, String lastName){
		EmployeeDetailsBean bean = new EmployeeDetailsBean();

		// Declare the request needed
		GetEmployeeDetailsRequest request = new GetEmployeeDetailsRequest();

		// Declare the response needed
		GetEmployeeDetailsResponse response = new GetEmployeeDetailsResponse();
		
		// Map the request
		Employee empQuery = new Employee();
		empQuery.setFirstName(firstName);
		empQuery.setLastName(lastName);
		request.setEmployee(empQuery);
		
		// Call the service method
		response = service.getEmployeeDetails(request);
		
		// Map the result response to the bean
		bean.setEmployeeDetail(response.getEmployeeDetails());
		bean.setExceptionError(response.getExceptionError());
		bean.setValidationErrors(response.getValidationErrors());
		
		// return bean for use in GUI
		return bean;
		
	}
	
	public EmployeeWorkstationBean getWorkstationMap(String firstName, String lastName){
		EmployeeWorkstationBean bean = new EmployeeWorkstationBean();

		// Declare the request needed
		GetWorkstationMapByNameRequest request = new GetWorkstationMapByNameRequest();

		// Declare the response needed
		GetWorkstationMapByNameResponse response = new GetWorkstationMapByNameResponse();
		
		// Map the request
		request.setFirstName(firstName);
		request.setLastName(lastName);
		
		// Call the service method
		response = service.getEmployeeWorkstationMap(request);
		
		// Map the result response to the bean
		bean.setWorkstationList(response.getWorkstationList());
		bean.setExceptionError(response.getExceptionError());
		bean.setValidationErrors(response.getValidationErrors());
		
		// return bean for use in GUI
		return bean;
		
	}
	public GetSeatCodesByFloorBean getCodesByFloor(String location, String floor){
		GetSeatCodesByFloorBean bean = new GetSeatCodesByFloorBean();

		// Declare the request needed
		GetSeatCodeByFloorRequest request = new GetSeatCodeByFloorRequest();

		// Declare the response needed
		GetSeatCodeByFloorResponse response = new GetSeatCodeByFloorResponse();
		
		// Map the request
		request.setLocation(location);
		request.setFloor(floor);
		
		// Call the service method
		response = service.getSeatmapByFloor(request);
		
		// Map the result response to the bean
		bean.setLocationSeatMap(response.getLocationSeatMap());
		bean.setExceptionError(response.getExceptionError());
		bean.setValidationErrors(response.getValidationErrors());
		
		// return bean for use in GUI
		return bean;
		
	}
	
	
	public ReportSeatPlanBean getReportSeatPlanList(String location_detail_id){
		ReportSeatPlanBean bean = new ReportSeatPlanBean();

		// Declare the request needed
		ReportRequest request = new ReportRequest();

		// Declare the response needed
		ReportResponse response = new ReportResponse();
		
		// Map the request
		request.setLocationDetailId(location_detail_id);
		
		
		// Call the service method
		response = service.getReportSeatPlanList(request);
		
		// Map the result response to the bean
		bean.setReportSeatPlanList(response.getSeatPlanResults());
		
		// return bean for use in GUI
		return bean;
		
	}
	

}
